﻿using Application.Dto;
using Application.IAppSrevices;
using AutoMapper;
using Domain.Entitys;
using Microsoft.AspNetCore.Mvc;

namespace UI.Controllers
{
    public class CFSKController : Controller
    {
        private readonly ICFSKService cFSKService;
        private readonly ICFFKService cFFKService;
        private readonly IMapper mapper;

        public CFSKController(ICFSKService cFSKService,ICFFKService cFFKService,IMapper mapper)
        {
            this.cFSKService = cFSKService;
            this.cFFKService = cFFKService;
            this.mapper = mapper;
        }
        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 分页查询级机构表数据
        /// </summary>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public IActionResult CFSKSelectFenYe(int currentPage,int pageSize)
        {
            FenYe<CFSK> fenYe = new FenYe<CFSK>()
            {
                CurrentPage = currentPage,
                PageSize = pageSize
            };
            cFSKService.CFSKSelectFenYe(fenYe);
            return Json(fenYe);
        }

        /// <summary>
        /// 添加2级机构表页面
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult CFSKInsert()
        {
            return View();
        }

        /// <summary>
        /// 查询1级结构编号下拉框
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> CFFKSelectOption()
        {
            return Json(await cFFKService.CFFKSelectOption());
        }

        /// <summary>
        /// 添加二级结构表数据
        /// </summary>
        /// <param name="cFSKAddDto"></param>
        /// <returns></returns>
        [HttpPost("CFSK/CFSKInsertAsync")]
        public async Task<IActionResult> CFSKInsertAsync(CFSKAddDto cFSKAddDto)
        {
            int num = await cFSKService.CFSKInsertAsync(cFSKAddDto);
            return Json(num);
        }

        /// <summary>
        /// 跳转修改页面
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult CFSKUpdate(int id)
        {
            TempData["id"] = id;
            return View();
        }

        /// <summary>
        /// 根据id查询对应的数据
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> CFSKSelectById()
        {
            int id = (int)TempData["id"];
            return Json(await cFSKService.CFSKSelectById(id));
        }

        /// <summary>
        /// 修改2级结构表数据
        /// </summary>
        /// <param name="cFSK"></param>
        /// <returns></returns>
        [HttpPut("CFSK/CFSKUpdateAsync")]
        public async Task<IActionResult> CFSKUpdateAsync(CFSK cFSK)
        {
            int num = await cFSKService.CFSKUpdateAsync(cFSK);
            return Json(num);
        }

        /// <summary>
        /// 删除2级结构表数据
        /// </summary>
        /// <param name="cFSK"></param>
        /// <returns></returns>
        [HttpDelete("CFSK/CFSKDeleteAsync")]
        public async Task<IActionResult> CFSKDeleteAsync(CFSKDeleteDto cFSK)
        {
            int num = await cFSKService.CFSKDeleteAsync(cFSK);
            return Json(num);
        }

        public async Task<IActionResult> CFSKSelectByCfkid(string fskid)
        {
            return Json(await cFSKService.CFSKSelectByCfkid(fskid));
        }
    }
}
